package com.goldendawn.lockscreen.recevier;

import com.goldendawn.lockscreen.tools.GolbVar;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class CallingRecevier extends BroadcastReceiver {
	
	private GolbVar golbVar;
	@Override
	public void onReceive(Context context, Intent intent) {
		golbVar=GolbVar.getInstance(context);

			// TODO Auto-generated method stub
			TelephonyManager telephonyManager = (TelephonyManager) context
					.getSystemService(Context.TELEPHONY_SERVICE);
			telephonyManager.listen(listener,
					PhoneStateListener.LISTEN_CALL_STATE);
	
	}

	PhoneStateListener listener=new PhoneStateListener(){

		@Override
		public void onCallStateChanged(int state, String incomingNumber) {
			// TODO Auto-generated method stub
			super.onCallStateChanged(state, incomingNumber);
			switch (state) {
			case TelephonyManager.CALL_STATE_IDLE:
				golbVar.setCalling(false);
				break;
			default :
				golbVar.setCalling(true);
				break;
			}
		}
		
	};
}
